package com.ysy.logistics.service.system.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysy.logistics.entities.system.MenuNode;
import com.ysy.logistics.entities.system.RoleMenu;
import com.ysy.logistics.entities.system.vo.TreeSelectNode;
import com.ysy.logistics.mapper.system.MenuNodeMapper;
import com.ysy.logistics.mapper.system.RoleMenuMapper;
import com.ysy.logistics.service.system.MenuNodeService;
import com.ysy.logistics.service.system.RoleMenuService;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassDescription:
 * @Author:姚斯羽
 * @Create:2025/3/19 10:16
 **/
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements RoleMenuService {

    @Resource
    private RoleMenuMapper roleMenuMapper;

    @Override
    public void deleteByRoleId(String id) {
        if (StringUtils.isBlank(id)){
            return;
        }
        LambdaQueryWrapper<RoleMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RoleMenu::getRoleId,id);
        this.remove(queryWrapper);
    }

    @Override
    public void addRoleMenu(String id, Integer[] permissionIds) {
        List<RoleMenu> roleMenuList = new ArrayList<>();
        for (Integer permissionId : permissionIds) {
            RoleMenu roleMenu = new RoleMenu();
            roleMenu.setRoleId(id);
            roleMenu.setMenuId(Long.valueOf(permissionId));
            roleMenuList.add(roleMenu);
        }
        roleMenuMapper.addList(roleMenuList);
    }
}
